﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Web_App___AWS_ELB_Monitor.Foundation
{
    public static class DateTimeExtensions
    {
        public static DateTimeOffset TimeToZero(this DateTimeOffset rawDate)
        {
            return rawDate.Add(-rawDate.TimeOfDay);
        }

        /// <summary>
        /// Keeps same time, but changes date to today. Helpful for normalizing values
        /// </summary>
        /// <param name="rawDate"></param>
        /// <returns></returns>
        public static DateTimeOffset TodaySameTime(this DateTimeOffset rawDate)
        {
            var dateNow = DateTimeOffset.UtcNow;
            return new DateTimeOffset(dateNow.Year,dateNow.Month, dateNow.Day,rawDate.Hour,rawDate.Minute,rawDate.Second,rawDate.Millisecond,TimeSpan.Zero);
        }

        /// <summary>
        /// Keeps same time, but changes date to today. Helpful for normalizing values
        /// </summary>
        /// <param name="rawDate"></param>
        /// <returns></returns>
        public static DateTime TodaySameTime(this DateTime rawDate)
        {
            var dateNow = DateTime.UtcNow;
            return new DateTime(dateNow.Year, dateNow.Month, dateNow.Day, rawDate.Hour, rawDate.Minute, rawDate.Second, rawDate.Millisecond, rawDate.Kind);
        }
    }
}